package com.java.comprehensive.arithmetic.leecode.tags.hashmap;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

/**
 * @program: comprehensive-service
 *
 * @description: 扎不同
 *
 * @author: 窦绍飞
 *
 * @create: 2021-12-24 14:51
 **/
public class LeetCode_389 {

	public static char findTheDifference(String s, String t) {
		Map<Character, Integer> map = new HashMap<>();
		for (int i = 0; i < s.length(); i++) {
			boolean b = map.containsKey(s.charAt(i));
			if (b) {
				Integer integer = map.get(s.charAt(i));
				integer++;
				map.put(s.charAt(i), integer);

			} else {
				map.put(s.charAt(i), 1);
			}
		}
		Map<Character, Integer> map_2 = new HashMap<>();
		for (int i = 0; i < t.length(); i++) {
			boolean b = map_2.containsKey(t.charAt(i));
			if (b) {
				Integer integer = map_2.get(t.charAt(i));
				integer++;
				map_2.put(t.charAt(i), integer);

			} else {
				map_2.put(t.charAt(i), 1);
			}
		}
		for (Map.Entry<Character, Integer> characterIntegerEntry : map_2.entrySet()) {
			Integer integer1 = map.get(characterIntegerEntry.getKey());
			if (integer1 == null || !integer1.equals(characterIntegerEntry.getValue())) {
				return characterIntegerEntry.getKey();
			}
		}
		return 'c';
	}

	public static void main(String[] args) {
		String s = "abcd", t = "abcde";
		char theDifference = findTheDifference(s, t);

		System.out.println(theDifference);
	}
}
